#ifndef _RDB_H_
#define _RDB_H_

#include <iostream>
#include <string>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <cstring>
#include "viRDBIcd.h"
#include "RDBHandler.h"
#include <tuple>

class RDB_MSG_NEED
{
public:
    RDB_OBJECT_STATE_t egoCar;
    std::vector<RDB_OBJECT_STATE_t> dynamicObjects;
    std::vector<RDB_OBJECT_STATE_t> staticObjects;
    std::vector<RDB_ROAD_POS_t> roadPos;
    std::vector<RDB_LANE_INFO_t> laneInfo;
    std::vector<RDB_ROADMARK_t> roadMark;
    std::vector<RDB_CONTACT_POINT_t> contactPoint;
    std::vector<RDB_TRAFFIC_SIGN_t> trafficSign;
    std::vector<RDB_ROAD_STATE_t> roadState;
    std::vector<RDB_ENVIRONMENT_t> environment;
    std::vector<RDB_DRIVER_CTRL_t> driverCtrl;
    std::vector<RDB_TRAFFIC_LIGHT_t> trafficLight;
    void clear();
};

//决策模块声明
std::tuple<double, double, double> decision(const RDB_MSG_NEED& rdbMsgNeed);
//解析包头
void parseRDBMessage(RDB_MSG_t* msg, bool& isImage, 
                    bool& sParseMessageEntry, RDB_MSG_NEED& rdbMsgNeed);
//解析每个包，一个包可能包含一条信息或多条同样大小的信息
int parseRDBMessageEntry(const double& simTime, const unsigned int& simFrame, 
    RDB_MSG_ENTRY_HDR_t* entryHdr, bool& sParseMessageEntry, RDB_MSG_NEED& rdbMsgNeed);
//标准或静态对象的状态信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_OBJECT_STATE_t & item, bool isExtended, RDB_MSG_NEED& rdbMsgNeed);
//给定实体的详细道路位置信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_ROAD_POS_t & item, RDB_MSG_NEED& rdbMsgNeed);
//给定实体的车道信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_LANE_INFO_t & item, RDB_MSG_NEED& rdbMsgNeed);
//交通车（通常是主车）的道路标记信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_ROADMARK_t & item, RDB_MSG_NEED& rdbMsgNeed);
//给定接触点的道路信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_CONTACT_POINT_t & item, RDB_MSG_NEED& rdbMsgNeed);
//关于交通标志对象的信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_TRAFFIC_SIGN_t & item, RDB_MSG_NEED& rdbMsgNeed);
//给定交通参与者的道路状态信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_ROAD_STATE_t & item, RDB_MSG_NEED& rdbMsgNeed);
//环境信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_ENVIRONMENT_t & item, RDB_MSG_NEED& rdbMsgNeed);
//来自模型或驱动模块的动态输入信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_DRIVER_CTRL_t & item, RDB_MSG_NEED& rdbMsgNeed);
//红绿灯及其状态的信息提取
void handleRDBitem(const double& simTime, const unsigned int& simFrame, 
                    RDB_TRAFFIC_LIGHT_t & item, bool isExtended, RDB_MSG_NEED& rdbMsgNeed);
//反控主车模块
void sendTrigger(int& sendSocket, const double& simTime, const unsigned int& simFrame);

#endif